package com.pth.test;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.pth.model.Notice;
import com.pth.service.NoticeService;

public class AutoComplateAction extends ActionSupport {

	private String key;
	private InputStream inputStream;  
	 
    public InputStream getResult(){  
          
        return inputStream;  
          
    }  
	
	private NoticeService noticeService;

	public void setKey(String key) {
		this.key = key;
	}

	public String getKey() {
		return key;
	}
	
	
	
@Override
public String execute() throws Exception {
	
	List<Notice> notices=noticeService.getNoticesOrderByScannum();
	Gson gson=new Gson();
	String result=gson.toJson(notices);
	// inputStream =new ByteArrayInputStream(result.getBytes("UTF-8"));
	HttpServletResponse resp=ServletActionContext.getResponse();
	HttpServletRequest req=ServletActionContext.getRequest();
	req.setCharacterEncoding("utf-8");
	resp.setCharacterEncoding("utf-8");
	PrintWriter out=resp.getWriter();
	out.println(result);
	out.flush();
	out.close();
	
	return SUCCESS;
}

public void setNoticeService(NoticeService noticeService) {
	this.noticeService = noticeService;
}

public NoticeService getNoticeService() {
	return noticeService;
}
	
}
